package cn.edu.cqvie.netty.nio;

import io.netty.buffer.ByteBufUtil;

import java.nio.Buffer;
import java.nio.ByteBuffer;

/**
 *
 * 分片Buffer
 *
 */
public class NioTest6 {

    public static void main(String[] args) {

        ByteBuffer buffer = ByteBuffer.allocate(10);

        for (int i=0; i < buffer.capacity(); ++i) {
            buffer.put((byte)i);
        }

        buffer.position(2);
        buffer.limit(6);

        ByteBuffer sliceBuffer = buffer.slice();
        for (int i=0; i< sliceBuffer.capacity(); ++i) {
            byte b = sliceBuffer.get(i);
            b*=2;
            sliceBuffer.put(i, b);
        }

        buffer.position(10);
        buffer.limit(buffer.capacity());

        while (buffer.hasRemaining()) {
            System.out.println(buffer.get());
        }
    }
}
